<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Dormitory</title>
	<link rel="shortcut icon" href="favicon.ico">
	<link rel="stylesheet" href="css/themes/default/jquery.mobile-1.4.3.min.css">
	<link rel="stylesheet" href="_assets/css/jqm-demos.css">
    <link rel="stylesheet" href="css/family.css">
	<script src="js/jquery.js"></script>
	<script src="_assets/js/index.js"></script>
	<script src="js/jquery.mobile-1.4.3.min.js"></script>
	<script src="js/dormitory.js"></script>
	<script>
		function login(id, pwd){
			var result = null;
			
			if(id == "admin" && pwd == "admin"){
				result = {
					id : "admin",
					name : "박촌장",
					guestHouseName : "게하"
				};
			}
			
			return result;
		}
		
		$(document).ready(function() {
			
			// 아이디 저장 체크
			if(localStorage.getItem("autoCheck") == "true"){
				$("#checkbox-mini-0").attr("checked",true).checkboxradio("refresh");
				$("#login-id").val(localStorage.getItem("login-id"));
			}
			
			// 로그인
			$("#login-login").click(function(){
				
				var id = jQuery.trim($("#login-id").val());
				var pwd = jQuery.trim($("#login-pwd").val());
				
				if(id == ""){
					alert("아이디를 입력하세요");
					$("#login-id").focus();
					return;
				}
				
				if(pwd == ""){
					alert("비밀번호를 입력하세요.");
					$("#login-pwd").focus();
					return;
				}
				
				if(login(id, pwd)){
					if($("#checkbox-mini-0").is(":checked")){
						localStorage.setItem("login-id", $("#login-id").val());
						localStorage.setItem("autoCheck","true");
					}else{
						localStorage.setItem("login-id", "");
						localStorage.setItem("autoCheck","false");
					}
					/*
					$.mobile.changePage("dashboard.html", {
						transition: "slide"//,
						//changeHash : false,
						//reloadPage : true
					});
					*/
					document.location.href = "dashboard.html";
				}else{
					alert("회원 정보가 올바르지 않습니다.");
				}
				
			});
			
			// 회원가입 화면으로 이동
			$("#login-join").click(function(){
				alert("개발자에게 문의 바랍니다.\nriuzzang@gmail.com");
				/*
				$.mobile.changePage("join.html", {
					transition: "slide"
				});
				*/
			});
			
		});
	</script>
</head>
<body>
<div data-role="page" class="jqm-demos jqm-home">

	<div data-role="header" class="jqm-header">
		<p>Version <span class="jqm-version"></span></p>
	</div><!-- /header -->

	<div role="main" class="ui-content jqm-content">
		<br>
		<h1><b>Dormitory</b></h1>
		
		<div class="ui-grid-a ui-responsive">
        	<div class="ui-block-a">
        		<div class="jqm-block-content">
        			<h3>Login</h3>

   					<input type="text" name="textinput-1" id="login-id" placeholder="아이디를 입력하세요" value="">
   					<input type="password" name="textinput-1" id="login-pwd" placeholder="비밀번호를 입력하세요" value="">
					
					<form>
					    <input type="checkbox" id="checkbox-mini-0" data-mini="true">
					    <label for="checkbox-mini-0">아이디 저장</label>
					</form>
					
					<form class="ui-grid-a">
						<div class="ui-block-a">
							<input type="button" value="회원가입" id="login-join">
						</div>
						<div class="ui-block-b">
							<input type="button" value="로그인" id="login-login">
						</div>
					</form>
					
        		</div>
        	</div>
        </div>

	</div><!-- /content -->

	<div data-role="footer" data-position="fixed" data-tap-toggle="false" class="jqm-footer">
		<p>도미토리 version <span class="jqm-version"></span></p>
		<p>Copyright 2014 Riuzzang</p>
	</div><!-- /footer -->
	
</div><!-- /page -->

</body>
</html>
